home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
BBS in a Box 7
/
BBS in a Box - Macintosh - Volume VII (BBS in a Box) (January 1993).iso
/
Files
/
Prog
/
Q-R
/
QB Graphics.sea
/
patterns.bas
< prev
next >
Wrap
BASIC Source File
|
1991-06-04
|
5KB
|
145 lines
'------------------------------------------------------------------------------
' TITLE: Patterns
' DATE: February 2, 1991
' AUTHOR: R. Gonzalez
'
' DESCRIPTION: Draw patterns on screen. REQUIRES COLOR OR GRAY-SCALE,
' unless you modify modify the code to eliminate the color-selection.
'
' COMPILING: Remove STATIC declarations, uncomment indicated lines
' Check: Include MBPCs & MBLCs, Include runtime code, Make all arrays static,
' Use default window & menu, (if available: Generate 68020 & 68881 code).
'
' (MODIFICATION HISTORY)
' DATE:
' AUTHOR:
' DESCRIPTION:
'------------------------------------------------------------------------------
' these variables may be shared among several subprograms:
DIM SHARED TRUE%,FALSE%,PI
' user defined functions must be declared at top of source file:
DEF FNrnd.color% = INT(RND*8) 'returns a random color
'------------------------------------------------------------------------------
' main procedure
'------------------------------------------------------------------------------
'MAIN
DIM color.value%(7)
DIM fcol%,bcol%,done% 'I like to declare all variables, array or otherwise
TRUE% = -1
FALSE% = 0
PI = 3.14159
initialize color.value%()
done% = FALSE%
RANDOMIZE TIMER 'seed random number generator with time
' Here's the main event loop:
WHILE NOT done%
set.colors fcol%,bcol%,color.value%()
CLS 'clear screen with background color
PRINT "Fore:";fcol%;"Back:";bcol%
draw.figure PI/60!
sleep 2!
check.if.done done%
WEND
END
'------------------------------------------------------------------------------
' initialize color/gray-scale values
'------------------------------------------------------------------------------
SUB initialize (color.value%()) STATIC
color.value%(0) = 30 'white white
color.value%(1) = 69 'very close to white yellow
color.value%(2) = 273 'light gray cyan
color.value%(3) = 137 'gray magenta
color.value%(4) = 341 'dark gray green
color.value%(5) = 409 'black or very close blue
color.value%(6) = 205 'black or very close red
color.value%(7) = 33 'black black
END SUB
'------------------------------------------------------------------------------
' set foreground and background colors
'------------------------------------------------------------------------------
SUB set.colors (col1%,col2%,color.value%()) STATIC
col1% = FNrnd.color%
col2% = FNrnd.color%
WHILE col1% = col2% 'avoid black-on-black, etc.
col1% = FNrnd.color%
WEND
forecolor color.value%(col1%) 'Toolbox call to set drawing color
backcolor color.value%(col2%) 'Toolbox call to set background color
END SUB
'------------------------------------------------------------------------------
' draw a random figure made up of lines.
' Since QuickBASIC is rather slow in making subprogram calls, it's best to avoid
' calling a subprogram in a critical loop, such as within the FOR loop below.
'------------------------------------------------------------------------------
SUB draw.figure (increment) STATIC
' for compiler only (since you can't have STATIC subprograms):
' dim window.width%,window.height%
' dim x,x1,x2,y1,y2,a,b,c,d,e,f,g,h
window.width% = WINDOW(2)/2! 'actively find window width
window.height% = WINDOW(3)/2! 'actively find window height
a = RND * 2!
b = RND * 2!
c = RND * 2!
d = RND * 2!
e = RND * PI * 2!
f = RND * PI * 2!
g = RND * PI * 2!
h = RND * PI * 2!
FOR x = 0! TO 2!*PI STEP increment
x1 = SIN(x * a + e) * window.width% * .95 + window.width%
y1 = SIN(x * b + f) * window.height% * .95 + window.height%
x2 = SIN(x * c + g) * window.width% * .95 + window.width%
y2 = SIN(x * d + h) * window.height% * .95 + window.height%
LINE (x1, y1)-(x2, y2) 'draw line using foreground color
NEXT
END SUB
'------------------------------------------------------------------------------
' change value of argument if mouse or any key is pressed
'------------------------------------------------------------------------------
SUB check.if.done (test%) STATIC
IF INKEY$ <> "" OR MOUSE(0) = 1 THEN
test% = TRUE%
END IF
END SUB
'------------------------------------------------------------------------------
' wait specified number of seconds
'------------------------------------------------------------------------------
SUB sleep (sleep.time) STATIC
' for compiler only:
' dim start.time
start.time = TIMER
WHILE TIMER < start.time + sleep.time
WEND
END SUB